package com.atwisdom.star.core.dao.pojo.basicClass;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.core.dao.pojo.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 
 * @TableName mesh_lib
 */
@TableName(value ="mesh_lib",autoResultMap = true)
@Data
public class MeshLib extends BaseEntity {
    /**
     * 主键标识
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;


    /**
     * 类型
     */
    @TableField(value = "type")
    private String type;


    /**
     * 名称
     */
    @TableField(value = "name")
    private String name;


    /**
     * 显示文件名
     */
    @TableField(value = "displayFileName")
    private String displayFileName;

    /**
     * 显示文件名
     */
    @TableField(value = "fileName")
    private String fileName;

    /**
     * 显示文件名
     */
    @TableField(value = "extendName")
    private String extendName;

    /**
     * 备注
     */
    @TableField(value = "comments")
    private String comments;


    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    /**
     * 获取摘要数据列
     *
     * @return 反回查询列
     */
    public static String[] fetchSimpleColumns() {
        List<String> columns = new ArrayList<>();
        columns.add("id");
        columns.add("type");
        columns.add("name");
        columns.add("fileName");
        columns.add("displayFileName");
        columns.add("extendName");
        columns.add("updatedBy");
        columns.add("updateTime");
        columns.add("createdBy");
        columns.add("createTime");
        return columns.toArray(new String[0]);
    }

    public MeshLib(){

    }

    /**
     * 有参构造方法
     *
     * @param jsonObject 参数
     */
    public MeshLib(JSONObject jsonObject) {
        Set<String> keys = jsonObject.keySet();
        this.id = keys.contains("id") ? jsonObject.getLong("id") : null;
        this.type = jsonObject.getString("type");
        this.name = jsonObject.getString("name");
        this.fileName = jsonObject.getString("fileName");
        this.displayFileName = jsonObject.getString("displayFileName");
        this.extendName = jsonObject.getString("extendName");
        this.comments = keys.contains("comments") ? jsonObject.getString("comments") : null;
    }

    /**
     * 将当前模型对象转成jsonObject
     *
     * @return 返回结果
     */
    public JSONObject fetchJsonObject() {
        JSONObject JsonObject = new JSONObject();
        JsonObject.put("id", this.id);
        JsonObject.put("type", this.type);
        JsonObject.put("name", this.name);
        JsonObject.put("fileName", this.fileName);
        JsonObject.put("displayFileName", this.displayFileName);
        JsonObject.put("extendName", this.extendName);
        JsonObject.put("comments", this.comments);
        JsonObject.put("createdBy", this.createdBy);
        JsonObject.put("createTime", this.createTime);
        JsonObject.put("updatedBy", this.updatedBy);
        JsonObject.put("updateTime", this.updateTime);
        return JsonObject;
    }
}